/**
  **************************************************************************
  * @file     main.c
  * @brief    main program
  **************************************************************************
  *                       Copyright notice & Disclaimer
  *
  * The software Board Support Package (BSP) that is made available to
  * download from Artery official website is the copyrighted work of Artery.
  * Artery authorizes customers to use, copy, and distribute the BSP
  * software and its related documentation for the purpose of design and
  * development in conjunction with Artery microcontrollers. Use of the
  * software is governed by this copyright notice and the following disclaimer.
  *
  * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  *
  **************************************************************************
**/

#include "at32f415_board.h"
#include "at32f415_clock.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "lcd_init.h"
#include "lcd.h"
#include "touch.h"
#include "pic.h"
#include "lvgl.h"
#include "lv_port_disp.h"
#include "lv_port_indev.h"
/*
lcd pin init:

SCK	  ---	PB15
MOSI  ---	PB14
RES	  ---	PB13
DC	  ---	PB12
BLK	  ---	PB11
MISO  ---	PB10
CS1	  ---	PB1
CS2	  ---	PB0
PEN	  ---	PA7



*/

/**
  * @brief  main function.
  * @param  none
  * @retval none
  */
int main(void)
{
	
	at32_board_init();
	
	lv_init();
	lv_port_disp_init();
	lv_port_indev_init();
	

	lv_obj_t *myBtn = lv_btn_create(lv_scr_act());                               
	lv_obj_set_pos(myBtn, 10, 10);                                               
	lv_obj_set_size(myBtn, 120, 50);                                             
 

	lv_obj_t *label_btn = lv_label_create(myBtn);                                
	lv_obj_align(label_btn, LV_ALIGN_CENTER, 0, 0);                              
	lv_label_set_text(label_btn, "Test");                                        


	lv_obj_t *myLabel = lv_label_create(lv_scr_act());                           
	lv_label_set_text(myLabel, "Hello world!");                                  
	lv_obj_align(myLabel, LV_ALIGN_CENTER, 0, 0);                                
	lv_obj_align_to(myBtn, myLabel, LV_ALIGN_OUT_TOP_MID, 0, -20);   
	
//	LCD_Fill(0,0,LCD_W,LCD_H,WHITE);
	
	while(1){
		delay_ms(1);
		
		static u8 mslvgl = 0;
		if(mslvgl++ >= 5){
			lv_timer_handler();
			mslvgl = 0;
		}
	}

}
